/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.workplan;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.workplan.Workplantype;

/**
 * @author Administrator (email:xxh@163.com)
 * @since 2013-03-21
 */
@Service("workplantypeService")
public class WorkplantypeServiceImpl implements WorkplantypeService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of Workplantype
     ****************************************/
    public void insert(Workplantype workplantype) throws Exception {
        workplantype.setTypeid(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(workplantype);
    }

    /****************************************
     * Update a instace of Workplantype
     ****************************************/
    public void update(Workplantype workplantype) throws Exception {
        iDataSet4iBatis.update(workplantype);
    }

    /****************************************
     * Delete a instace of Workplantype
     ****************************************/
    public void delete(Workplantype workplantype) throws Exception {
        iDataSet4iBatis.delete(workplantype);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(Workplantype workplantype) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(Workplantype workplantype) throws Exception {
        String statementId = workplantype.getStatmentId();
        String mainId = workplantype.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> workplantypeList = new ArrayList<BaseModel>();
        for (String id : ids) {
            Workplantype model = new Workplantype();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            workplantypeList.add(model);
        }
        iDataSet4iBatis.batchDelete(workplantypeList);
    }

    /****************************************
     * Query instaces of Workplantype
     ****************************************/
    public List<BaseModel> queryAsList(Workplantype workplantype) throws Exception {
        String queryListStatement = "";
        if (workplantype.isPaging()) {
            queryListStatement = workplantype.getStatmentId();
            workplantype.setStatmentId("Workplantype.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(workplantype);
            workplantype.setTotalCount(baseModel.getTotalCount());
            workplantype.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(workplantype);
    }

    /****************************************
     * Query a instaces of Workplantype
     ****************************************/
    public BaseModel queryAsObject(Workplantype workplantype) throws Exception {
        return iDataSet4iBatis.queryAsObject(workplantype);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
